package cn.com.shopec.erp.product.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.transform.Transformers;
import org.hibernate.type.StandardBasicTypes;
import org.springframework.stereotype.Repository;

import cn.com.shopec.erp.common.orm.impl.HibernateEntityDao;
import cn.com.shopec.erp.product.dao.ICommodityCatDao;
import cn.com.shopec.erp.product.entity.CommodityCat;
import cn.com.shopec.erp.product.vo.CommodityCatVo;

/** 
 * @ClassName: CommodityCatDaoImpl 
 * @Description: 商品分类表的dao实现
 *  
 */
@Repository
public class CommodityCatDaoImpl extends HibernateEntityDao<CommodityCat> implements ICommodityCatDao {

	/**
	 * 根据分类编号查询品牌名称
	 */
	@Override
	public List<CommodityCatVo> getCommodityCatNo(String catNo) {
			StringBuffer sql = new StringBuffer();
			sql.append("SELECT t.id as id, "
					+ "t.CAT_NO as catNo, "
					+ "t.CAT_NAME as catName, "
					+ "t.CAT_PNO as catPno, "
					+ "t.DESCRIPTION as description, "
					+ "t.DELETE_FLAG as deleteFlag, "
					+ "t.CREATE_TIME as createTime, "
					+ "t.UPDATE_TIME as updateTime, "
					+ "t.NO as no  , "
					+ "b.BRAND_NAME as brandName, "
					+ "b.BRAND_No as brandNo "
					+ "FROM TBL_COMMODITY_CAT t "
					+ "INNER JOIN tbl_cat_brand c ON t.CAT_NO = c.CAT_NO "
					+ "INNER JOIN tbl_brand b ON c.BRAND_NO = b.BRAND_NO "
					+ "WHERE t.CAT_NO = '"+catNo+"' and t.DELETE_FLAG = 1 ");
			Query query= getSession().createSQLQuery(sql.toString())
					.addScalar("id",StandardBasicTypes.STRING)
					.addScalar("catNo",StandardBasicTypes.STRING)
					.addScalar("catName",StandardBasicTypes.STRING)
					.addScalar("catPno",StandardBasicTypes.STRING)
					.addScalar("description",StandardBasicTypes.STRING)
					.addScalar("deleteFlag",StandardBasicTypes.INTEGER)
					.addScalar("createTime",StandardBasicTypes.INTEGER)
					.addScalar("updateTime",StandardBasicTypes.STRING)
					.addScalar("no",StandardBasicTypes.STRING)
					.addScalar("brandName",StandardBasicTypes.STRING)
					.addScalar("brandNo",StandardBasicTypes.STRING);
			query.setResultTransformer(Transformers.aliasToBean(CommodityCatVo.class));
			List<CommodityCatVo> purchase = query.list();
			
		return purchase;
	}

	
}
